import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
import userManageRouter from './modules/userManage' // 用户管理路由
import equityManageRouter from './modules/equityManage' // 权益管理路由
import dataManageRouter from './modules/dataManage' // 数据管理路由
import faniManageRouter from './modules/faniManage' // 财务管理路由
import systemRouter from './modules/systemManage'
/**
 * 注意：子菜单仅在 route children.length >= 1 时出现
 * hidden：如果设置为true，则项目不会显示在侧边栏中（默认为false）
 * alwaysShow: true 如果设置为 true，将始终显示根菜单
 * 如果不设置 alwaysShow，当 item 有多个子路由时，
 * 会变成嵌套模式，否则不显示根菜单
 * redirect: noRedirect 如果设置 noRedirect 将不会在面包屑中重定向
 * name:'router-name' <keep-alive> 使用的名称（必须设置！！！）
 * meta：{
    roles: ['admin','editor'] 控制页面角色（可以设置多个角色）
    title: 'title' 侧边栏和面包屑中显示的名称（推荐设置）
    icon: 'svg-name'/'el-icon-x' 侧边栏中显示的图标
    noCache: true 如果设置为true，则页面不会被缓存（默认为false）
    affix: true 如果设置为true，标签将附加在标签视图中
    breadcrumb: false 如果设置为 false，该项目将隐藏在面包屑中（默认为 true）
    activeMenu: '/example/list' 如果设置路径，侧边栏会高亮你设置的路径
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{ // 切换路由
    path: '/redirect',
    component: Layout,
    hidden: false,
    children: [{
      path: '/redirect/:path(.*)',
      component: () => import('@/views/redirect/index')
    }]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },


  {
    path: '/payGateWay',
    component: () => import('@/layout/components/payMent/payGateWay.vue'),
    hidden: true
  },
  {
    path: '/error',
    component: Layout,
    redirect: 'noRedirect',
    name: 'ErrorPages',
    hidden: true,
    meta: {
      title: 'Error Pages',
      icon: '404'
    },
    children: [{
        path: '401',
        component: () => import('@/views/error-page/401'),
        name: 'Page401',
        meta: {
          title: '401',
          noCache: true
        }
      },
      {
        path: '404',
        component: () => import('@/views/error-page/404'),
        name: 'Page404',
        meta: {
          title: '404',
          noCache: true
        }
      }
    ]
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: "dashboard",
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      name: 'Dashboard',
      meta: {
        title: '主页',
        icon: 'dashboard',
        affix: true
      }
    }]
  },
  // {
  //   path: '*',
  //   redirect: '/404',
  //   hidden: true
  // },
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  userManageRouter,
  equityManageRouter,
  dataManageRouter,
  faniManageRouter,
  {
    path: '/leaderboard',
    component: Layout,
    name: "leaderboard",
    meta: {
      title: "排行榜", 
      icon: 'chart'
    },
    children: [
      {
      path: 'leaderboarddeploy',
      component: () => import('@/views/leaderboard/leaderboarddeploy.vue'),
      name: 'leaderboarddeploy',
      meta: {
        title: '排行榜配置',
        icon: 'chart',
        noCache: true
      }
    },
      {
      path: 'leaderboardreport',
      component: () => import('@/views/leaderboard/leaderboardreport.vue'),
      name: 'leaderboardreport',
      meta: {
        title: '排行榜报表',
        icon: 'component',
        noCache: true
      }
    },
    ]
  },
  // Organization
  {
    path: '/Organization',
    component: Layout,
    name: "Organization",
    children: [{
      path: 'Organization',
      component: () => import('@/views/Organization'),
      name: 'Organization',
      meta: {
        title: '公司组织架构',
        icon: 'component',
        noCache: true
      }
    }]
  },

  {
    path: '/Activity',
    component: Layout,
    name: "Activity",
    children: [{
      path: 'Activity',
      component: () => import('@/views/Activity'),
      name: 'Activity',
      meta: {
        title: '活动管理',
        icon: 'el-icon-s-ticket',
        noCache: true
      }
    }]
  },
  {
    path: '/shareSetting',
    component: Layout,
    name: 'shareSetting',
    meta: {
      title: '分享管理',
      icon: 'people'
    },
    children: [{
        path: 'setting',
        component: () => import('@/views/ShareSetting/shareSetting.vue'),
        name: 'setting',
        meta: {
          title: '分享设置',
          noCache: true
        }
      },
      {
        path: 'poster',
        component: () => import('@/views/ShareSetting/poster.vue'),
        name: 'poster',
        meta: {
          title: '海报管理',
          noCache: true
        }
      }
    ]
  },

  {
    path: '/messageSetting',
    component: Layout,
    name: "messageSetting",
    children: [{
      path: 'messageSetting',
      component: () => import('@/views/MessageSetting'),
      name: 'messageSetting',
      meta: {
        title: '消息设置',
        icon: 'wechat',
        noCache: true
      }
    }]
  },
  systemRouter,
  // {
  //   path: '/icon',
  //   component: Layout,
  //   hidden: false,
  //   children: [{
  //     path: 'index',
  //     component: () => import('@/views/icons/index'),
  //     name: 'Icons',
  //     meta: {
  //       title: 'Icons',
  //       icon: 'icon',
  //       noCache: true
  //     }
  //   }]
  // },


  // {  //留着此页面做换肤功能时可参考
  //   path: '/theme',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/theme/index'),
  //       name: 'Theme',
  //       meta: { title: 'Theme', icon: 'theme' }
  //     }
  //   ]
  // },
  // 404 page must be placed at the end !!!


]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
